local path "C:\Users\pgi1\Dropbox\Coal 2021 _ Joe Peter\Bank Regressions\"
cd "`path'\data"
set seed 100
set more off
clear



use  loan_year_vars_dataset, clear

//edit if lender=="BofA Securities"

bysort ultimateparentid year: keep if _n==1
xtset ultimateparentid year
sum 
keep if year>=2000 & year<=2020


//replace loans_mtr_total=0 if loans_total==0


// table with more controls

// table with more controls

est clear

xtreg loans_mtr_ln treated  log_assets asset_growth_3 loans_total_lag3_ln  loans_related_lag3_ln y_*, fe vce(cluster ultimateparentid)
est store e1
estadd local fes "Bank and Year"

xtreg loans_mtr_ln treated_company loans_related_lag3_ln loans_total_lag3_ln log_assets asset_growth_3 y_*, fe vce(cluster ultimateparentid)
est store e2
estadd local fes "Bank and Year"


xtreg loans_mtr_ln treated_project loans_related_lag3_ln loans_total_lag3_ln  log_assets  asset_growth_3 y_*, fe vce(cluster ultimateparentid)
est store e3
estadd local fes "Bank and Year"


xtreg loans_mtr_ln treated_enhanced log_assets asset_growth_3 loans_total_lag3_ln  loans_related_lag3_ln y_*, fe vce(cluster ultimateparentid)
est store e4
estadd local fes "Bank and Year"

esttab e1 e2 e3 e4 using "`path'\tables\table-3.rtf",  replace compress nogaps se onecell b(3) modelwidth(6) ///
title("Table 4 Panel A. Number of Loans to MTR-affiliated borrowers") mtitles( "Any"  "Company" "Project" "Enhanced" ) ///
stats(fes r2_a  N , fmt(%9.0fc %9.3fc %9.0fc ) labels("Fixed Effects" "Adj. R-squared" "Observations" ) ) ///
label collabels(none)  starlevels(* 0.10 ** 0.05 *** 0.01) nonote ///
order(treated treated_company treated_project treated_enhanced log_assets asset_growth_3 loans_total_lag3_ln  loans_related_lag3_ln) keep(treated treated_company treated_project treated_enhanced log_assets asset_growth_3 loans_total_lag3_ln  loans_related_lag3_ln)


est clear

xtreg loans_mtr_total treated  log_assets asset_growth_3 loans_total_lag3_ln  loans_related_lag3_ln y_*, fe vce(cluster ultimateparentid)
est store e1
estadd local fes "Bank and Year"

xtreg loans_mtr_total treated_company loans_related_lag3_ln loans_total_lag3_ln log_assets asset_growth_3 y_*, fe vce(cluster ultimateparentid)
est store e2
estadd local fes "Bank and Year"


xtreg loans_mtr_total treated_project loans_related_lag3_ln loans_total_lag3_ln  log_assets  asset_growth_3 y_*, fe vce(cluster ultimateparentid)
est store e3
estadd local fes "Bank and Year"


xtreg loans_mtr_total treated_enhanced log_assets asset_growth_3 loans_total_lag3_ln  loans_related_lag3_ln y_*, fe vce(cluster ultimateparentid)
est store e4
estadd local fes "Bank and Year"

esttab e1 e2 e3 e4 using "`path'\tables\table-3.rtf",  append compress nogaps se onecell b(3) modelwidth(6) ///
title("Panel B. Ratio of Loans Amounts to MTR-affiliated borrowers to Total Loan Amounts") mtitles( "Any"  "Company" "Project" "Enhanced" ) ///
stats(fes r2_a  N , fmt(%9.0fc %9.3fc %9.0fc ) labels("Fixed Effects" "Adj. R-squared" "Observations" ) ) ///
label collabels(none)  starlevels(* 0.10 ** 0.05 *** 0.01) nonote ///
order(treated treated_company treated_project treated_enhanced log_assets asset_growth_3 loans_total_lag3_ln  loans_related_lag3_ln) keep(treated treated_company treated_project treated_enhanced log_assets asset_growth_3 loans_total_lag3_ln  loans_related_lag3_ln)

exit